import axios,{InternalAxiosRequestConfig,AxiosResponse,AxiosError} from '@ohos/axios'

export  const instance =axios.create({
  baseURL:'http://200.200.200.13:8080/',
  timeout:2000,
});
instance.interceptors.request.use(
  (config) => {
    // 这里可以添加简单的日志
    console.log(`Sending request to: ${config.url}`);
    return config;
  },
  (error) => {
    // 请求错误直接返回
    return Promise.reject(error);
  }
);

// 响应拦截器（最简单版本）
instance.interceptors.response.use(
  (response) => {
    // 直接返回整个响应对象
    if (response.data.code ===100200) {
      return response.data.data;
    }else {
      return Promise.reject(response.data.message)
    }

  },
  (error) => {
    // 响应错误直接返回
    return Promise.reject(error);
  }
);

export default instance;


//4 post put delete get
export  class HttpX{
  get<T>(url:string,params?:Object){
    return instance.get<null,T>(url,{
      params
    })
  }
  delete<T>(url:string,params?:Object){
    return instance.delete<null,T>(url,{
      params
    })
  }
  post<T>(url:string,data?:Object){
    return instance.post<null,T>(url,data)
  }
  put<T>(url:string,data?:Object){
    return instance.put<null,T>(url,data)
  }
}

export const httpx:HttpX =new HttpX();

